﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class caDemo
    {
       

        #region Main方法
        /// <summary>
        /// 主程序入口Main()
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            for (int i = 1; i <= 9; i++)
            {
                for (int j = 1; j <= i; j++)
                {
                    Console.Write("{0}*{1}={2}  ", i, j, i * j);
                }
                Console.WriteLine();
            }
            Console.WriteLine();

            //GetXQ();
            //Console.WriteLine();
            //GetXQY();

            Console.Write("请按照格式 XXXX-XX-XX 输入年月日： ");
            CalcWeekDay myCalcWeekDay = new CalcWeekDay();
            String strDate = Console.ReadLine().Trim();
            String[] strDates = strDate.Split(new char[] { '-'});
            int temp=0;
            if (Int32.TryParse(strDates[0],out temp))
            {
                myCalcWeekDay.Year = Int32.Parse(strDates[0]);
            }
            if (Int32.TryParse(strDates[1], out temp))
            {
                myCalcWeekDay.Month = Int32.Parse(strDates[1]);
            }
            if (Int32.TryParse(strDates[2], out temp))
            {
                myCalcWeekDay.Day = Int32.Parse(strDates[2]);
            }
            Console.WriteLine();
            //打印星期几
            myCalcWeekDay.PrintWeekDayByDate();
            Console.WriteLine();
            myCalcWeekDay.PrintWeekDay();
            Console.ReadKey();
            //强类型
            List<int> list = new List<int>();

        }

        #endregion

        /// <summary>
        ///  //万年历 1900.1.1 星期一 
        ///  打出2010-5 月的日历
        ///  1、5月1号是星期几？
        ///  2、1900.1.1--1.7=7天%7+1就是星期几
        ///  3、总天数=（1990--2009）*365（算上闰年）+2010年1.1--4.30的总天数  
        ///  4、y%400||（y%4==0&&y%100!=0）的就是闰年
        ///  5、m小于5的话，叠加后续的数值
        /// </summary>
        public static void GetXQ()
        {
            int totalDay = 0;

            #region 求天数第一部分
            for (int y = 1900; y <= 2009; y++)
            {
                if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))
                {
                    totalDay += 366;
                }
                else
                {
                    totalDay += 365;
                }
            }
            #endregion

            #region 求天数第二部分
            for (int m = 1; m <= 4; m++)
            {
                switch (m)
                {
                    case 1:
                        totalDay += 31;
                        break;
                    case 2:
                        totalDay += 28;
                        break;
                    case 3:
                        totalDay += 31;
                        break;
                    case 4:
                        totalDay += 30;
                        break;
                    case 5:
                        totalDay += 31;
                        break;
                    case 6:
                        totalDay += 30;
                        break;
                    case 7:
                        totalDay += 31;
                        break;
                    case 8:
                        totalDay += 31;
                        break;
                    case 9:
                        totalDay += 30;
                        break;
                    case 10:
                        totalDay += 31;
                        break;
                    case 11:
                        totalDay += 30;
                        break;
                    case 12:
                        totalDay += 31;
                        break;
                    default:
                        break;
                }
            }
            #endregion

            #region 打印星期几
            Console.WriteLine("总天数：{0}", totalDay + 1);
            switch ((totalDay + 1) % 7 + 1)
            {
                case 1:
                    Console.WriteLine("星期日");
                    break;
                case 2:
                    Console.WriteLine("星期一");
                    break;
                case 3:
                    Console.WriteLine("星期二");
                    break;
                case 4:
                    Console.WriteLine("星期三");
                    break;
                case 5:
                    Console.WriteLine("星期四");
                    break;
                case 6:
                    Console.WriteLine("星期五");
                    break;
                case 7:
                    Console.WriteLine("星期六");
                    break;
                default:
                    break;
            }
            #endregion
        }

        /// <summary>
        /// 
        /// </summary>
        public static void GetXQY()
        {
            int year = 0, x = 0, y = 0, t = 0;
            #region 第一部分
            for (y = 1900; y <= 2009; y++)
            {
                if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))
                {
                    year += 366;
                }
                else
                {
                    year += 365;
                }
            }
            #endregion
            #region 第二部分
            for (x = 1; x <= 4; x++)
            {
                switch (x)
                {
                    case 1:
                        year = year + 31;
                        break;
                    case 3:
                         year = year + 31;
                        break;
                    case 5:
                        year = year + 31;
                        break;
                    case 7:
                        year = year + 31;
                        break;
                    case 8:
                        year = year + 31;
                        break;
                    case 10:
                        year = year + 31;
                        break;
                    case 12:
                        year = year + 31;
                        break;
                    case 2:
                        if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0))
                            year = year + 29;
                        else
                            year = year + 28;
                        break;
                    case 4:
                         year = year + 30;
                        break;
                    case 6:
                        year = year + 30;
                        break;
                    case 9:
                        year = year + 30;
                        break;
                    case 11:
                        year = year + 30;
                        break;
                    default:
                        break;
                }
            }
            #endregion
            #region 打印星期几
            Console.WriteLine("{0}", year + 1);
            t = (year + 1) % 7 + 1;
            switch (t)
            {
                case 1: Console.WriteLine("sunday"); break;
                case 2: Console.WriteLine("monday"); break;
                case 3: Console.WriteLine("tuesday"); break;
                case 4: Console.WriteLine("wednesday"); break;
                case 5: Console.WriteLine("thursday"); break;
                case 6: Console.WriteLine("frideday"); break;
                case 7: Console.WriteLine("saturday"); break;
                default: break;
            }
           
            #endregion
        }


    }
}
